package com.huike.service.impl;


import cn.hutool.core.date.DateTime;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huike.core.page.TableDataInfo;
import com.huike.dto.domain.Course;
import com.huike.dto.CourseDto;
import com.huike.mapper.CourseMapper;
import com.huike.service.CourseService;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

@Service
@Slf4j
public class CourseServiceImpl extends ServiceImpl<CourseMapper,Course> implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    /**
     * 查询课程管理列表
     *
     * @param course 课程管理
     * @return 课程管理集合
     */
    @Override
    public List<Course> selectTbCourseList(Course course) {
        return courseMapper.selectCourseList(course);
    }

    /**
     *
     * @param dto
     * @return
     */
    @Override
    public TableDataInfo<Course> selectAll(CourseDto dto) {
        return null;
    }


    /**
     * 新增课程
     * @param course
     */
    @Override
    public void insert(Course course) {
        course.setCreateTime(LocalDateTime.now());
        course.setCode(UUID.randomUUID().toString().replace("-","").substring(0,8));
        courseMapper.insert(course);
    }

    /**
     * 删除单个
     * @param id
     */
    @Override
    public void delete(Long id) {
        courseMapper.deleteById(id);
    }

    /**
     * 查询课程
     * @param id
     * @return
     */
    @Override
    public Course selectById(Long id) {
        Course course = new Course();
        BeanUtils.copyProperties(super.getById(id),course);
        return course;
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Override
    public int deleteCourseByIds(Long[] ids) {
        return courseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 修改课程
     * @param dto
     */
    @Override
    public void updateCourse(CourseDto dto) {
        Course course = new Course();
        BeanUtils.copyProperties(dto,course);
        course.setUpdateTime(DateTime.now());
        courseMapper.updateById(course);
    }
}
